function getYPGSearchUrl(freeSearchOp, matchingAllTerms, matchingSearchHash) {
    return "/addama-rest/dudley-sample/path/datasource/YPG/search?" + freeSearchOp + matchingAllTerms +
           "&PROJECTION=genotype" +
           "&PROJECTION=parentA" +
           "&PROJECTION=parentAlpha" +
           "&PROJECTION=crossingRef" +
           "&PROJECTION=matingType" +
           "&PROJECTION=boxNumber" +
           "&PROJECTION=dateFrozen" +
           "&PROJECTION=comments" +
           "&PROJECTION=position" +
           "&PROJECTION=alias" +
           "&PROJECTION=siblings" +
           "&PROJECTION=tetrad" +
           "&PROJECTION=status" +
           matchingSearchHash;
}

/*
http://ravioli:8080/solr/select
/?q=ypgCrossingRef:YCR*&wt=json&rows=50&
fl=ypgKey,ypgBoxNumber,ypgCrossingRef,ypgMatingType,ypgComments
 */
function getYPGSolrUrl(searchTerm) {
    return "/solr/select/?" + "q=" + searchTerm + "&wt=json&rows=5000&" +
           "fl=ypgKey,ypgBoxNumber,ypgCrossingRef,ypgMatingType,ypgGenotype,ypgParentA,ypgParentAlpha,ypgAlias,ypgTetrad,ypgStatus,ypgPosition,ypgComments,ypgDateFrozen,ypgSiblings";
}


function getYPGPagingColumns() {
    return [
        {
            name: 'indexNum',
            type: 'float'
        },
        {
            name: 'name'
        },
        {
            name: 'matingType'
        },
        {
            name: 'genotype'
        },
        {
            name: 'parentA'
        },
        {
            name: 'parentAlpha'
        },
        {
            name: 'crossingRef'
        },
        {
            name: 'boxNumber'
        },
        {
            name: 'dateFrozen'
        },
        {
            name: 'comments'
        },
        {
            name: 'position'
        },
        {
            name: 'siblings'
        },
        {
            name: 'alias'
        },
        {
            name: 'tetrad'
        },
        {
            name: 'status'
        }
    ];
}

function translateYPGResultToJson(jsonSearchArray) {
    var jsonObj = [];
    var ypgKey = jsonSearchArray.name;
    jsonObj[0] = ypgKey.substring(3, ypgKey.length);
    jsonObj[1] = jsonSearchArray.name;
    jsonObj[2] = jsonSearchArray.matingType;
    jsonObj[3] = jsonSearchArray.genotype;
    jsonObj[4] = jsonSearchArray.parentA;
    jsonObj[5] = jsonSearchArray.parentAlpha;
    jsonObj[6] = jsonSearchArray.crossingRef;
    jsonObj[7] = jsonSearchArray.boxNumber;
    jsonObj[8] = jsonSearchArray.dateFrozen;
    jsonObj[9] = jsonSearchArray.comments;
    jsonObj[10] = jsonSearchArray.position;
    jsonObj[11] = jsonSearchArray.siblings;
    jsonObj[12] = jsonSearchArray.alias;
    jsonObj[13] = jsonSearchArray.tetrad;
    if (!jsonSearchArray.status) {
        jsonObj[14] = "VIABLE";
    } else {
        jsonObj[14] = jsonSearchArray.status;
    }
    return jsonObj;
}

function translateYPGSolr(jsonSearchArray) {
    var jsonObj = [];
    var ypgKey = jsonSearchArray.ypgKey;
    jsonObj[0] = ypgKey.substring(3, ypgKey.length);
    jsonObj[1] = ypgKey;
    jsonObj[2] = jsonSearchArray.ypgMatingType;
    jsonObj[3] = jsonSearchArray.ypgGenotype;
    jsonObj[4] = jsonSearchArray.ypgParentA;
    jsonObj[5] = jsonSearchArray.ypgParentAlpha;
    jsonObj[6] = jsonSearchArray.ypgCrossingRef;
    jsonObj[7] = jsonSearchArray.ypgBoxNumber;
    jsonObj[8] = jsonSearchArray.ypgDateFrozen;
    jsonObj[9] = jsonSearchArray.ypgComments;
    jsonObj[10] = jsonSearchArray.ypgPosition;
    jsonObj[11] = jsonSearchArray.ypgSiblings;
    jsonObj[12] = jsonSearchArray.ypgAlias;
    jsonObj[13] = jsonSearchArray.ypgTetrad;
    if (!jsonSearchArray.ypgStatus) {
        jsonObj[14] = "VIABLE";
    } else {
        jsonObj[14] = jsonSearchArray.ypgStatus;
    }
    return jsonObj;
}

var ypgSolrTranslator = function(jsonSearchArray){
    var jsonObj = [];
    var ypgKey = jsonSearchArray.ypgKey;
    jsonObj[0] = ypgKey.substring(3, ypgKey.length);
    jsonObj[1] = ypgKey;
    jsonObj[2] = jsonSearchArray.ypgMatingType;
    jsonObj[3] = jsonSearchArray.ypgGenotype;
    jsonObj[4] = jsonSearchArray.ypgParentA;
    jsonObj[5] = jsonSearchArray.ypgParentAlpha;
    jsonObj[6] = jsonSearchArray.ypgCrossingRef;
    jsonObj[7] = jsonSearchArray.ypgBoxNumber;
    jsonObj[8] = jsonSearchArray.ypgDateFrozen;
    jsonObj[9] = jsonSearchArray.ypgComments;
    jsonObj[10] = jsonSearchArray.ypgPosition;
    jsonObj[11] = jsonSearchArray.ypgSiblings;
    jsonObj[12] = jsonSearchArray.ypgAlias;
    jsonObj[13] = jsonSearchArray.ypgTetrad;
    if (!jsonSearchArray.ypgStatus) {
        jsonObj[14] = "VIABLE";
    } else {
        jsonObj[14] = jsonSearchArray.ypgStatus;
    }
    return jsonObj;
};


function getYPGSearchOptionsArray() {
    return [
        ['all', 'All'],
        ['ypgCrossingRef', 'ypgCrossingRef'],
        ['ypgMatingType', 'ypgMatingType'],
        ['ypgGenotype', 'ypgGenotype'],
        ['ypgStrainSource', 'ypgStrainSource'],
        ['ypgDateFrozen', 'ypgDateFrozen'],
        ['ypgParentA', 'ypgParentA'],
        ['ypgParentAlpha', 'ypgParentAlpha'],
        ['ypgSiblings', 'ypgSiblings'],
        ['ypgTetrad', 'ypgTetrad'],
        ['ypgStatus', 'ypgStatus'],
        ['ypgAlias', 'ypgAlias'],
        ['ypgBoxNumber', 'ypgBoxNumber'],
        ['ypgPosition', 'ypgPosition'],
        ['ypgComments', 'ypgComments']

    ];
}

function getYPGSearchColumnHeaders() {
    return  [
        {
            header: 'Index',
            width: 50,
            sortable: true,
            dataIndex: 'indexNum'
        },
        {
            id:'name',
            header: 'Name',
            width: 60,
            sortable: true,
            dataIndex: 'name'
        },
        {
            header: 'Alias',
            hidden: true,
            dataIndex: 'alias'
        },
        {
            header: 'Mating Type',
            width: 80,
            sortable: true,
            dataIndex: 'matingType'
        },
        {
            header: 'Genotype',
            width: 80,
            sortable: true,
            dataIndex: 'genotype'
        },
        {
            header: 'Parent A',
            width: 80,
            sortable: true,
            dataIndex: 'parentA'
        },
        {
            header: 'Parent Alpha',
            width: 80,
            sortable: true,
            dataIndex: 'parentAlpha'
        },
        {
            header: 'Crossing',
            width: 70,
            sortable: true,
            dataIndex: 'crossingRef'
        },
        {
            header: 'Box Number',
            width: 80,
            sortable: true,
            dataIndex: 'boxNumber'
        },
        {
            header: 'Position',
            width: 70,
            sortable: true,
            dataIndex: 'position'
        },
        {
            header: 'Date Frozen',
            hidden: true,
            dataIndex: 'dateFrozen'
        },
        {
            header: 'Comments',
            hidden: true,
            dataIndex: 'comments'
        },
        {
            header: 'Siblings',
            hidden: true,
            dataIndex: 'siblings'
        },
        {
            header: 'Status',
            width: 80,
            sortable: true,
            dataIndex: 'status'
        }
    ];
}

function initYPGStrainJson(strainHash) {
    strainHash.matingType = 'Undetermined';
    strainHash.genotype = undefined;
    strainHash.parentA = undefined;
    strainHash.parentAlpha = undefined;
    strainHash.siblings = undefined;
    strainHash.crossingRef = undefined;
    strainHash.boxNumber = undefined;
    strainHash.position = "";
    strainHash.dateFrozen = undefined;
    strainHash.sequencingData = "";

}

function populateYPGJson(strainHash, g) {
    strainHash.name = g.getSelectionModel().getSelected().data.name;
    strainHash.matingType = g.getSelectionModel().getSelected().data.matingType;
    strainHash.genotype = g.getSelectionModel().getSelected().data.genotype;
    strainHash.parentA = g.getSelectionModel().getSelected().data.parentA;
    strainHash.parentAlpha = g.getSelectionModel().getSelected().data.parentAlpha;
    strainHash.siblings = g.getSelectionModel().getSelected().data.siblings;
    strainHash.crossingRef = g.getSelectionModel().getSelected().data.crossingRef;
    strainHash.boxNumber = g.getSelectionModel().getSelected().data.boxNumber;
    strainHash.position = g.getSelectionModel().getSelected().data.position;
    strainHash.dateFrozen = g.getSelectionModel().getSelected().data.dateFrozen;
    strainHash.comments = g.getSelectionModel().getSelected().data.comments;
    strainHash.alias = g.getSelectionModel().getSelected().data.alias;
    strainHash.tetrad = g.getSelectionModel().getSelected().data.tetrad;
    strainHash.status = g.getSelectionModel().getSelected().data.status;
}

function validateCreateUpdateYPG() {

    /*if (Ext.getCmp("ypgStrainNameId").getValue() == null || Ext.getCmp("ypgStrainNameId").getValue() == "") {
     Ext.Msg.alert('Error', 'Strain name is required.');
     return false;
     } else if (Ext.getCmp("ypgAliasId").getValue() == null || Ext.getCmp("ypgAliasId").getValue() == "") {
     Ext.Msg.alert('Error', 'Alias is required.');
     return false;
     } else if (Ext.getCmp("ypgGenotypeId").getValue() == null || Ext.getCmp("ypgGenotypeId").getValue() == "") {
     Ext.Msg.alert('Error', 'Genotype info is required.');
     return false;
     } else if (Ext.getCmp("ypgBoxNumberId").getValue() == null || Ext.getCmp("ypgBoxNumberId").getValue() == "") {
     Ext.Msg.alert('Error', 'Box number is required and must be numeric.');
     return false;
     } else if (Ext.getCmp("ypgDateFrozenId").getValue() == null || Ext.getCmp("ypgDateFrozenId").getValue() == "") {
     Ext.Msg.alert('Error', 'Date Frozen is required and must be in MO/DT/YYYY.');
     return false;
     } else if (Ext.getCmp("ypgParentAId").getValue() == null || Ext.getCmp("ypgParentAId").getValue() == "") {
     Ext.Msg.alert('Error', 'Parent A is required.');
     return false;
     } else if (Ext.getCmp("ypgParentAlphaId").getValue() == null || Ext.getCmp("ypgParentAlphaId").getValue() == "") {
     Ext.Msg.alert('Error', 'Parent Alpha is required.');
     return false;
     }*/


    return true;
}

function getImageConditionsArray(imageInputJson) {
    var allConditions = imageInputJson["conditionsAllId"];
    if (allConditions) {
        return ['CAF', 'CHR', 'COP', 'ERB', 'ETH', 'GLY', 'HYG', 'KAN', 'NAT', 'RAP', 'SHI', 'SLO', 'YPD'];
    } else {
        var conditionsArray = [];
        conditionsArray[0] = imageInputJson["cafId"];
        if (imageInputJson["cafId"]) {
            conditionsArray[0] = "CAF";
        }
        conditionsArray[1] = imageInputJson["chrId"];
        if (imageInputJson["chrId"]) {
            conditionsArray[1] = "CHR";
        }
        conditionsArray[2] = imageInputJson["copId"];
        if (imageInputJson["copId"]) {
            conditionsArray[2] = "COP";
        }
        conditionsArray[3] = imageInputJson["erbId"];
        if (imageInputJson["erbId"]) {
            conditionsArray[3] = "ERB";
        }
        conditionsArray[4] = imageInputJson["ethId"];
        if (imageInputJson["ethId"]) {
            conditionsArray[4] = "ETH";
        }
        conditionsArray[5] = imageInputJson["glyId"];
        if (imageInputJson["glyId"]) {
            conditionsArray[5] = "GLY";
        }
        conditionsArray[6] = imageInputJson["hygId"];
        if (imageInputJson["hygId"]) {
            conditionsArray[6] = "HYG";
        }
        conditionsArray[7] = imageInputJson["kanId"];
        if (imageInputJson["kanId"]) {
            conditionsArray[7] = "KAN";
        }
        conditionsArray[8] = imageInputJson["natId"];
        if (imageInputJson["natId"]) {
            conditionsArray[8] = "NAT";
        }
        conditionsArray[9] = imageInputJson["rapId"];
        if (imageInputJson["rapId"]) {
            conditionsArray[9] = "RAP";
        }
        conditionsArray[10] = imageInputJson["shiId"];
        if (imageInputJson["shiId"]) {
            conditionsArray[10] = "SHI";
        }
        conditionsArray[11] = imageInputJson["sloId"];
        if (imageInputJson["sloId"]) {
            conditionsArray[11] = "SLO";
        }
        conditionsArray[12] = imageInputJson["ypdId"];
        if (imageInputJson["ypdId"]) {
            conditionsArray[12] = "YPD";
        }
        return conditionsArray;
    }
}

function getImageDaysArray() {
    return ['1', '2', '3', '4', '5', '6', '7'];
}

function getImageGroupsArray() {
    return ['A', 'B'];
}
